package cn.zyq.ykb.controller.mgt.task;

import cn.zyq.ykb.beans.task.HomeChart;
import cn.zyq.ykb.service.task.HomeChartService;
import cn.zyq.ykb.system.annotation.Log;
import cn.zyq.ykb.system.common.BaseController;
import cn.zyq.ykb.system.common.PageParam;
import cn.zyq.ykb.system.ry.enums.BusinessType;
import cn.zyq.ykb.system.ry.util.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 首页-轮播图Controller
 *
 * @author SystemAuth
 * @date 2023-06-01
 */

@RestController(value = "MgtHomeChartController")
@RequestMapping("/mgt/homeChart")
@Api(tags = "首页-轮播图接口")
public class HomeChartController extends BaseController {

    @Autowired
    private HomeChartService homeChartService;

    /**
     * 查询首页-轮播图列表
     */
    @ApiOperation(value = "列表", response = HomeChart.class)
    @PostMapping("/list")
    public Object list(@RequestBody PageParam pageParam) {
        return this.homeChartService.selectHomeChartList(pageParam);
    }

     /**
      * 导出首页-轮播图列表
      */
     @ApiOperation(value = "导出")
     @Log(title = "首页-轮播图" , businessType = BusinessType.EXPORT)
     @PostMapping("/export")
     public void export(HttpServletResponse response, HomeChart homeChart) {
         List<HomeChart> list = homeChartService.selectHomeChartList(homeChart);
         ExcelUtil<HomeChart> util = new ExcelUtil<HomeChart>(HomeChart. class);
         util.exportExcel(response, list, "首页-轮播图数据");
     }

    /**
     * 获取首页-轮播图详细信息
     */
    @ApiOperation(value = "详情", response = HomeChart.class)
    @GetMapping(value = "/{homeChartID}")
    public Object getInfo(@PathVariable("homeChartID") Integer homeChartID) {
        return this.homeChartService.selectHomeChartByHomeChartID(homeChartID);
    }
    /**
     * 获取首页-轮播图详细信息
     */
    @ApiOperation(value = "详情", response = HomeChart.class)
    @GetMapping(value = "/detail/{serviceID}")
    public Object getInfo(@PathVariable(value = "serviceID") String serviceID) {
        return this.homeChartService.selectHomeChartByServiceID(serviceID);
    }

    /**
     * 新增首页-轮播图
     */
    @ApiOperation(value = "新增")
    @Log(title = "首页-轮播图", businessType = BusinessType.INSERT)
    @PostMapping
    public Object add(@RequestBody HomeChart homeChart) {
        return this.homeChartService.insertHomeChart(homeChart);
    }

    /**
     * 修改首页-轮播图
     */
    @ApiOperation(value = "编辑")
    @Log(title = "首页-轮播图", businessType = BusinessType.UPDATE)
    @PutMapping
    public Object edit(@RequestBody HomeChart homeChart) {
        return this.homeChartService.updateHomeChart(homeChart);
    }

    /**
     * 删除首页-轮播图
     */
    @ApiOperation(value = "删除")
    @Log(title = "首页-轮播图", businessType = BusinessType.DELETE)
    @DeleteMapping("/{homeChartIDs}")
    public Object remove(@PathVariable Integer[] homeChartIDs) {
        return this.homeChartService.deleteHomeChartByHomeChartIDs(homeChartIDs);
    }
}
